//
//  YBMineVideoBitratePopupVC.swift
//  Moonlight
//
//  Created by Penlon Kim on 2023/11/1.
//  Copyright © 2023 Moonlight Game Streaming Project. All rights reserved.
//

import UIKit
import SnapKit

class YBMineVideoBitratePopupVC: BaseMaskVC {
    
    // MARK: Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(bgView)
        bgView.addSubviews([titleLabel, desLabel, bitrateLabel, slider, cancelBtn, confirmBtn])
        
        bgView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.equalTo(kScreenWidth*0.84)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(18)
            make.top.equalTo(20).priority(.high)
            make.height.equalTo(24)
        }
        
        desLabel.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(7)
            make.left.right.equalToSuperview().inset(16)
            make.height.equalTo(20).priority(.medium)
        }
        
        bitrateLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(desLabel.snp.bottom).offset(12)
            make.height.equalTo(30).priority(.medium)
        }
        
        slider.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(16)
            make.centerX.equalToSuperview()
            make.top.equalTo(bitrateLabel.snp.bottom).offset(16)
        }
        
        confirmBtn.snp.makeConstraints { make in
            make.top.equalTo(slider.snp.bottom).offset(16)
            make.right.equalTo(-16)
            make.bottom.equalTo(-16).priority(.high)
        }
        
        cancelBtn.snp.makeConstraints { make in
            make.centerY.equalTo(confirmBtn)
            make.right.equalTo(confirmBtn.snp.left).offset(-24)
        }
        
    }
    
    // MARK: - lazy
    private lazy var bgView: UIView = {
        let view = UIView(color: .lightWhiteDark27)
        view.bk_addStyleWith(cornerRadius: 8, corners: .allCorners)
        return view
    }()
    
    private lazy var titleLabel = self.bk_addLabel(text: "视频比特率", font: .systemFont(ofSize: 20, weight: .medium), bgColor: .clear, textColor: .lightBlack51DarkLight230)
    
    private lazy var desLabel = self.bk_addLabel(text: "高码率提升图像质量。低码率提升在较慢网络中的串流体验。", font: .systemFont(ofSize: 15), bgColor: .clear, textColor: ColorDef.gray153)
    
    private lazy var bitrateLabel = self.bk_addLabel(text: "20.0 Mbps", font: .systemFont(ofSize: 22, weight: .medium), bgColor: .clear, textColor: .lightBlack51DarkLight230)
    
    private lazy var slider: BKCustomSlider = {
        $0.delegate = self
        $0.minimumValue = 0.5
        $0.maximumValue = 150.0
        $0.value = 20.0
        $0.minimumTrackTintColor = .blue
        $0.maximumTrackTintColor = ColorDef.gray153
        $0.thumbTintColor = .white
        $0.trackCornerRadius = 1.5
        return $0
    }(BKCustomSlider())
    
    private lazy var cancelBtn: UIButton = {
        let btn = self.bk_addButton(title: "取消", font: .systemFont(ofSize: 15), bgColor: .clear, titleColor: .red)
        btn.bk_addTarget { [weak self] sender in
            self?.dismiss(animated: true)
        }
        return btn
    }()
    
    private lazy var confirmBtn: UIButton = {
        let btn = self.bk_addButton(title: "确定", font: .systemFont(ofSize: 15), bgColor: .clear, titleColor: .blue)
        btn.bk_addTarget { [weak self] sender in
            
        }
        return btn
    }()
    
}

// MARK: - BKCustomSliderDelegate代理

extension YBMineVideoBitratePopupVC: BKCustomSliderDelegate {
    func currentValue(_ value: Float) {
        bitrateLabel.text = String(format: "%.1f Mbps", value)
    }
}
